//
//  GoodsDetailCell.m
//  danpin
//
//  Created by chuangjia on 26/6/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "GoodsDetailCell.h"

#import "UIButtonView.h"
#import "ZUIImageView.h"
@interface GoodsDetailCell ()
{
    
}
@property (nonatomic, strong) UIView *bgView;
@property(nonatomic,strong)ZUIImageView *imagesView;
@property(nonatomic,strong)RTLabel *titleLabel;
@property(nonatomic,strong)UILabel *ppriceLable;
@end
@implementation GoodsDetailCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        _bgView.backgroundColor =[UIColor whiteColor];//UIColorFromRGB(0xf4f4f4);
        _bgView.layer.cornerRadius = 3;
        _bgView.layer.borderWidth = 0.5;
        _bgView.layer.borderColor = UIColorFromRGB(0x999999).CGColor;
        [self.contentView addSubview:_bgView];
        
        _imagesView =[[ZUIImageView alloc] initWithFrame:CGRectZero];
        _imagesView.contentMode = UIViewContentModeScaleAspectFit;
        _imagesView.backgroundColor =UIColorFromRGB(0xffffff);
        [self.contentView addSubview:_imagesView];
        _titleLabel =[[RTLabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*13,0)];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = [UIColor darkGrayColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font =FONT(14);
        _titleLabel.lineSpacing =LSpacing;
        [self.contentView addSubview:_titleLabel];
        
        _ppriceLable =[[UILabel alloc] initWithFrame:CGRectZero];
        _ppriceLable.backgroundColor = [UIColor clearColor];
        _ppriceLable.textColor = [UIColor grayColor];
        _ppriceLable.textAlignment = NSTextAlignmentLeft;
        _ppriceLable.font = FONT(12);
        [self.contentView addSubview:_ppriceLable];
        
    }
    return self;
}
-(void)dealloc
{
    self.data=nil;
    self.imagesView=nil;
    self.titleLabel=nil;
    self.ppriceLable=nil;
    self.bgView =nil;
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
- (void)drawRect:(CGRect)rect {
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key = key;
    self.indexPath=indexPath;
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    
    _bgView.frame=CGRectMake(PHOTO_FRAME_WIDTH, 0, DEVICE_WIDTH - PHOTO_FRAME_WIDTH*2, PHOTO_FRAME_WIDTH*10);
    _imagesView.frame =CGRectMake(PHOTO_FRAME_WIDTH*2,PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*8, PHOTO_FRAME_WIDTH*8);
    NSString *ustr =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"largePicURL"]] replaceNullString];
    _imagesView.imageUrl = ustr;
    _imagesView.placeholderImage =[UIImage imageNamed:@"listcellimage.png"];
    
    NSString *brand =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"brand"]] replaceNullString];

    NSString *test =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"title"]] replaceNullString];
    if (brand && brand.length>0) {
        test = [NSString stringWithFormat:@"%@ - %@",brand,test];
    }
    [_titleLabel setText:test];
    CGSize optimumSize = [_titleLabel optimumSize];
    CGFloat h =optimumSize.height;
    if (h>70) {
        h=70;
    }
    _titleLabel.frame =CGRectMake(_imagesView.frame.origin.x+_imagesView.frame.size.width+PHOTO_FRAME_WIDTH, _imagesView.frame.origin.y, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*13, h);
    
    _ppriceLable.frame=CGRectMake(_imagesView.frame.origin.x+_imagesView.frame.size.width+PHOTO_FRAME_WIDTH,_imagesView.frame.origin.y+_imagesView.frame.size.height-20, 200, 20);
    _ppriceLable.text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"price_str"]] replaceNullString];
    [self layoutSubviews];
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    return PHOTO_FRAME_WIDTH*10+PHOTO_TIME_PADDING;
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)handleSingleTapFrom
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_taobao,nil,self.data,self.key,self.indexPath);
    }
}

@end
